package paint;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;

public class DefaultPaintButton extends PaintComponent {
	private String text;

	private int x;
	private int y;

	private Color textColor = Color.WHITE;
	private Color backgroundColor;
	private Color outlineColor;

	public DefaultPaintButton(int x, int y, String text, Color textColor, Color backgroundColor, Color outlineColor) {
		super(new Rectangle(x, y, 0, 0));
		this.x = x;
		this.y = y;
		this.text = text;
		this.textColor = textColor;
		this.backgroundColor = backgroundColor;
		this.outlineColor = outlineColor;
	}

	@Override
	public void setLocation(int x, int y) {
		bounds.x = x;
		bounds.y = y;
		this.x = x;
		this.y = y;
	}

	public void setColor(Color color) {
		backgroundColor = color;
	}

	@Override
	public void paint(Graphics g) {
		Rectangle textBounds = g.getFontMetrics().getStringBounds(text, g).getBounds();
		textBounds.width += 4;
		textBounds.height += 4;
		textBounds.x = x;
		textBounds.y = y;
		bounds = textBounds;

		Graphics2D g2 = (Graphics2D) g;
		GradientPaint gp = new GradientPaint(x, y, backgroundColor, x, textBounds.height + y, new Color(0, 0, 0, 200));
		g2.setPaint(gp);
		g.fillRect(x, y, textBounds.width, textBounds.height);

		g.setColor(outlineColor);
		g.drawRect(x, y, textBounds.width, textBounds.height);

		g.setColor(textColor);
		g.drawString(text, x + 2, y + 12);
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
